<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>EVENT</title>
</head>
<body>
  <h1>canvas 事件使用event.region属性判断对象</h1>
  <mark>需要开启chrome实验功能（chrome://flags[experimental canvas features] ）</mark>
  <canvas width="800" height="600"></canvas>
  <script>
    var cvs = document.querySelector('canvas');
        ctx = cvs.getContext('2d');
    cvs.addEventListener("mousemove", function(event){
      if(event.region) {
        alert("you are on" + event.region);
      }
    });

    // eyes
    ctx.beginPath();
    ctx.arc(70, 80, 10, 0, 2 * Math.PI, false);
    ctx.arc(130, 80, 10, 0, 2 * Math.PI, false);
    ctx.fill();
    ctx.addHitRegion({id: "eyes"});
    // mouth
    ctx.beginPath();
    ctx.arc(100, 110, 10, 0, 2 * Math.PI, false);
    ctx.fill();
    ctx.addHitRegion({id: "mouth"});
  </script>
</body>
</html>